package cn.zlj.pethome.org.controller;

import cn.zlj.pethome.basic.QueryResult;
import cn.zlj.pethome.basic.annotation.LogAnno;
import cn.zlj.pethome.basic.query.BaseQuery;
import cn.zlj.pethome.basic.util.AjaxResult;
import cn.zlj.pethome.org.domain.TSystemdictionarytype;
import cn.zlj.pethome.org.mapper.DictionaryMapper;
import cn.zlj.pethome.org.service.DtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dt")
@LogAnno
public class DtController {
    @Autowired
    DtService dtService;
    @Autowired
    DictionaryMapper dictionaryMapper;
    @GetMapping
    @LogAnno(method = "查询所有字典类型",methodDes = "list")
    public List<TSystemdictionarytype> list(){
        return dtService.findAll();
    }

    @PostMapping
    @LogAnno(method = "查询字典类型分页列表")
    public QueryResult<TSystemdictionarytype> queryPage(@RequestBody BaseQuery query) {
        QueryResult<TSystemdictionarytype> result = dtService.queryByPage(query);
        return result;
    }

    @PutMapping
    @LogAnno(method = "增加或者修改字典类型")
    public AjaxResult saveAndUpdate(@RequestBody TSystemdictionarytype t){
        if(t.getId()==null){
            dtService.add(t);
        }else {
            dtService.update(t);
        }
        return  AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    @LogAnno(method = "根据id删除字典类型")
    public AjaxResult del(@PathVariable("id") Long id){
        dtService.delete(id);
        dictionaryMapper.deleteByty(id);
        return  AjaxResult.me().success();
    }

    @PatchMapping
    @LogAnno(method = "根据id批量删除字典类型")
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        dtService.batchDel(ids);
        return AjaxResult.me().success();
    }

}
